using System;
using L=Science.Physics.GeneralPhysics;

namespace Serway.Chapter04
{
	/// <summary>
	/// Example05: That's Quite an Arm!
	/// A stone is thrown from the top of a building upward at 
	/// an angle of 30.0^{\circle} to the horizontal with an initial speed 
	/// of 20.0 m/s, as shown in Figure 4.14. If the height of 
	/// the building is 45.0 m,
	/// (A) how long does it take the stone to reach the ground?
	/// (B) What is the speed of the stone just before it strikes 
	/// the ground?
	/// </summary>
	public class Example05
	{
		public Example05()
		{
		}
		private string result;
		public string Result
		{
			get{return result;}
		}
		public void Compute()
		{
			L.Velocity v = new L.Velocity();
			v.X = 20.0*Math.Cos(30.0*Math.PI/180.0);
			v.Y = 20.0*Math.Sin(30.0*Math.PI/180.0);
            Science.Mathematics.Calculus.PolynomialFunction poly = new Science.Mathematics.Calculus.PolynomialFunction();
			poly.MaximumPower = 2;
			poly.Which = 0;
			poly.Coefficient = 45.0;
			poly.Which = 1;
			poly.Coefficient = v.Y;
			poly.Which = 2;
			poly.Coefficient = -0.5*L.Constant.AccelerationOfGravity;
			poly.FindRoot();
			double time1 = poly.Root[0].Real;
			double time2 = poly.Root[1].Real;
			//(A)
			if(time2 > time1) result+=Convert.ToString(time2);
			else result+=Convert.ToString(time1);
			//(B)
			L.Velocity vv = new L.Velocity();
			vv.X = v.X;
			vv.Y = v.Y - L.Constant.AccelerationOfGravity*time2;
			L.Speed sp = new L.Speed(vv);
			result+="   "+Convert.ToString(sp.Magnitude);
		}
	}
}
